package com.zhiwei.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhiwei.mapper.StockMapper;
import com.zhiwei.pojo.Stock;
import com.zhiwei.vo.PageResult;
import com.zhiwei.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class StockServiceImpl implements StockService{
    @Autowired
    private StockMapper stockMapper;

    @Override
    public List<Stock> getStockList(PageResult pageResult) {
        QueryWrapper<Stock> wrapper = new QueryWrapper<>();
        wrapper.eq("repository_id", pageResult.getType())
        .like(StringUtils.hasLength(pageResult.getQuery()),"material_id", pageResult.getQuery());
        List<Stock> stocks = stockMapper.selectList(wrapper);
        return stocks;
    }

    @Override
    public int updateStatus(Integer id) {
        Stock stock = stockMapper.selectById(id);
        stock.setDeleteFlag(!stock.getDeleteFlag());
        return stockMapper.updateById(stock);
    }
}
